package org.pku_uestc.hackathon;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;

public class MainActivity extends Activity implements AnimationListener, OnClickListener {
	
	private Animation translateUp;
	private Animation alphaAdd;
	
	private ImageView image;
	private Button addBtn, silentBtn, lightBtn, notificationBtn;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		image = (ImageView) findViewById(R.id.image);
		addBtn = (Button) findViewById(R.id.add_btn);
		silentBtn = (Button) findViewById(R.id.silent_btn);
		lightBtn = (Button) findViewById(R.id.light_btn);
		notificationBtn = (Button) findViewById(R.id.notification_btn);
		translateUp = AnimationUtils.loadAnimation(this, R.anim.bulb_translate);
		alphaAdd = AnimationUtils.loadAnimation(this, R.anim.add_alpha_in);
		addBtn.setOnClickListener(this);
		silentBtn.setOnClickListener(this);
		lightBtn.setOnClickListener(this);
		notificationBtn.setOnClickListener(this);
		translateUp.setAnimationListener(this);
		alphaAdd.setAnimationListener(this);
		addBtn.setVisibility(View.GONE);
		image.startAnimation(translateUp);
	}
	
 	@Override
	public void onClick(View v) {
 		Intent i = null;
 		switch(v.getId()) {
		case R.id.add_btn:
			break;
		case R.id.silent_btn:
			i = new Intent(this, SilentActivity.class);
			break;
		case R.id.notification_btn:
			break;
		case R.id.light_btn:
			i = new Intent(this, LightsActivity.class);
			break;
		}
 		if(i!=null) {
 			i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
 			startActivity(i);
 		}
	}

	@Override
	public void onAnimationEnd(Animation animation) {
		if (animation.equals(translateUp)) {
			addBtn.setVisibility(View.VISIBLE);
			addBtn.startAnimation(alphaAdd);
		} else if (animation.equals(alphaAdd)) {
		}
	}

	@Override
	public void onAnimationRepeat(Animation animation) {
		
	}

	@Override
	public void onAnimationStart(Animation animation) {
		
	}

}
